<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const posts = [
            { title: 'T Love Javascript', author: '张三', id: 1 },
            { title: 'CSS', author: '李四', id: 2 }
            // { title: 'dev' author:'ss'}
        ];
        const authors = [
            { name: '张三', hometown:'丰城', bio: '面向对象编程'}
        ]

        function getPostById(id) {
            // id  找到文章
            // const post = posts.find(post => post.id === id);
            // const { author } = post;
            // console.log(authors.find(item => item.name == author))
            // return post;
            return new Promise((resolve) => {
                // resolve();
                console.log('+++++')
                setTimeout(() => {
                    const post = posts.find(post => post.id == id)
                    if (!post) {
                        
                    }
                    console.log(post)
                    resolve();
                }, 200);
            })
        }
        getPostById(1)
            .then(() => {
                console.log('////')
            })
        // console.log(getPostById(1))
        // posts.push({
        //     title: 'Dev tools weklits',
        //     author: 'me',
        //     id: 3
        // })
        // localStorage.setItem('posts', JSON.stringify(posts))
        // console.log(JSON.stringify(posts))
    </script>
</body>
</html>